package demo;

import java.util.Scanner;

public class StringDemo05 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入Email:");
        String email = sc.next();
        email = email.toLowerCase();
        int atIndex = email.indexOf("@");
        int doIndex = email.indexOf(".");
        if (atIndex == -1 || doIndex == -1) {
            System.out.println("Email不合法,因为没有@和.");
            return;
        }if (atIndex > doIndex) {
            System.out.println("不合法，因为@不可以在.的后面");
            return;
        }
        if (email.startsWith("@") || email.endsWith(".")) {
            System.out.println("不合法，因为不能以@开头，不能以.结尾");
            return;
        }
        String[] array = email.split("@");
        if (array.length != 2) {
            System.out.println("不合法，因为@只能出现一次");
        }
        System.out.println("Email合法");


    }
}
